﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Facebook;
using System.Net;
using System.Text;
using Newtonsoft.Json;
using System.Web.Script.Serialization;
using System.IO;
using System.Collections.Specialized;

namespace Cecropia.Service
{
    public class FaceBookService
    {
        private Facebook.FacebookClient cliente;

        public FaceBookService(string token)
        {
            NameValueCollection ResponseNV = HttpUtility.ParseQueryString(token);
            cliente = new FacebookClient(ResponseNV["access_token"].ToString());
        }

        public Person getMe()
        {
            return cliente.Get<Person>("/me");
        }

        public List<Post> getFriendFeed(string userId)
        {
            return cliente.Get<Posts>("/" + userId + "/feed?limit=50").data;
        }

        public Person getFriend(string friendId)
        {
            return cliente.Get<Person>("/" + friendId);
        }

        public List<Person> getFriendList()
        {
            return cliente.Get<FacebookFriend>("/me/friends").data;
        }

        public List<Post> getFeedList()
        {
            return cliente.Get<Posts>("/me/home").data;
        }

        public void post(String msg, String userId)
        {
            Dictionary<String, string> postArgs = new Dictionary<String, string>();
            postArgs["message"] = msg;
            object postado = cliente.Post("/" + userId + "/feed", postArgs);
        }
    }
}